package com.gxuwz.attend.web.servlet;

import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * 页面控制器基类,封装页面跳转方式（应用内的请求转发|重定向到其他站点,包括应用本身）的处理过程。
 * @author amu_1115@126.com
 * @version 1.0
 */
public class BaseHttpServlet extends HttpServlet {
     protected final String  ErrorPage_500="/error/500.jsp";
    /**
     * 转发方式跳转处理
     * @param req
     * @param resp
     * @param path-对应请求的url 如:/user?action=edit
     * @throws ServletException
     * @throws IOException
     */
    protected void doDispatch(HttpServletRequest req, HttpServletResponse resp,String path)throws ServletException, IOException{
        RequestDispatcher dispatcher =req.getRequestDispatcher(path);
        dispatcher.forward(req,resp);
    }

    /**
     * 重定向方式跳转处理
     * @param req
     * @param resp
     * @param location -包括host(http://172.17.4.200)、port(:8080)、应用上下文(/attend)、请求路径(/user)、请求参数(?action=add)
     *                    如： http://172.17.4.200:8080/attend/user?action=add
     *                         https:www.baidu.com
     * @throws ServletException
     * @throws IOException
     */
    protected static void doRedirect(HttpServletRequest req, HttpServletResponse resp,String location)throws ServletException,IOException{
        resp.sendRedirect(location);
    }

}
